package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/07 11:56
 **/
public class Day23_5_Num6138_LongestIdealString {
    class Solution {
        public int longestIdealString(String s, int k) {
            int count[] = new int[26], max = 0;
            for (char c : s.toCharArray()) {
                for (int i = Math.max('a', c - k) - 'a'; i <= Math.min('z', c + k) - 'a'; i++) {
                    count[c - 'a'] = Math.max(count[c - 'a'], count[i]);
                }
                max = Math.max(max, ++count[c - 'a']);
            }
            return max;
        }
    }
}